hello guys i am new in csla 2 days learn by practice i tried new asp project connectiong to sqlserver 2012
i start doing IDalManager which contain GetProvider
public interface IDalManagerCslaExample:IDisposable
{
T GetProvider<T>() where T : class;
}
also i creat DalManagerClass which implemnt IDalManager Interface
public class DalManagerCslaExample:IDalManagerCslaExample
{
private static readonly string TypeMask =
typeof(DalManagerCslaExample).FullName.Replace("DalManagerCslaExample",@"{0}");
public ConnectionManager<SqlConnection> ConnectionManager {get; private set;}
public DalManagerCslaExample()
{
try
{
//calling connection string from web.config
ConnectionManager = ConnectionManager<SqlConnection>.GetManager("CslaExample");
}
catch (ConfigurationErrorsException ex)
{
if (ConnectionManager == null)
{
throw new ArgumentException(string.Format("ConnectionString {0} Couldnt be found","CslaExample"));
}
throw;
}
}
private const string BaseNamespace = "CslaExample.DataAccess";
public T GetProvider<T>() where T : class
{
string typeName;
var namespaceDiff = typeof(T).Namespace.Length - BaseNamespace.Length;
if (namespaceDiff > 0)
typeName = string.Format(TypeMask, typeof(T).Namespace.Substring(BaseNamespace.Length + 1,
namespaceDiff - 1)) + "." + typeof(T).Name.Substring(1);
else
typeName = string.Format(TypeMask, typeof(T).Name.Substring(1));
var type = Type.GetType(typeName);
if (typeName != null)
return Activator.CreateInstance(type) as T;
throw new NotImplementedException(typeName);
}
then i created dalFactory class
public class DalFactoryCslaExample
{
private static Type _daltype;
public static IDalManagerCslaExample GetManager()
{
if (_daltype == null)
{
var dalTypeName = ConfigurationManager.AppSettings["CslaExample.DalManagerType"];
if (!string.IsNullOrEmpty(dalTypeName))
_daltype = Type.GetType(dalTypeName);
else
throw new NullReferenceException("CslaExample.DalManagerType");
if (_daltype == null)
throw new ArgumentNullException(string.Format("Type {0} couldnt be found", dalTypeName));
}
return (IDalManagerCslaExample)Activator.CreateInstance(_daltype);
}
}
and on web.config i add thos lines to consume the DalManagerType
<appSettings>
<add key="CslaExample.DalManagerType" value="CslaExample.DataAccess.Sql.DalManagerCslaExample,CslaExample"/>
</appSettings>
<connectionStrings>
<add name="CslaExample" connectionString="Data Source=192.168.1.3;Initial Catalog=FinalInvintoryDesign;User ID=sa;Password=123"
providerName="System.Data.SqlClient" />
</connectionStrings>
and all thos classes i did in 1 project but in sperated folders what exactly i miss and plz if some one have free tutorial explain this data access Technic that will be greaaat help
never mind guys it worked all i need is fixing my namespace in config file but i still ask fir help good tutorial to explain how data access work please hope no one tell me buy using csla 4 or some video training from store i am absoultly 100 % it worth every benny but unfornutly i dont have a mastercard to buy it from internet
Copyright (c) Marimer LLC