Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property Injection enabled #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
using System.Diagnostics.Contracts;
using System.Linq;
using System.Windows.Input;
using FreshTinyIoC;

namespace FreshMvvmSampleApp
{
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class ContactListPageModel : FreshBasePageModel
{
IDatabaseService _databaseService;

public ContactListPageModel (IDatabaseService databaseService)
{
_databaseService = databaseService;
}
[TinyIocInject]
public IDatabaseService _databaseService { get; set; }

public ObservableCollection<Contact> Contacts { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ namespace FreshMvvmSampleApp
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class ContactPageModel : FreshBasePageModel
{
IDatabaseService _dataService;
public IDatabaseService _dataService { get; set; }

public ContactPageModel (IDatabaseService dataService)
public ContactPageModel ()
{
_dataService = dataService;

this.WhenAny(HandleContactChanged, o => o.Contact);
}

Expand Down
2 changes: 1 addition & 1 deletion src/FreshIOC/FreshTinyIOC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3424,7 +3424,7 @@ private static ObjectConstructor CreateObjectConstructionDelegateWithCache(Const
private void BuildUpInternal(object input, ResolveOptions resolveOptions)
{
var properties = from property in input.GetType().GetProperties()
where (property.GetGetMethod() != null) && (property.GetSetMethod() != null) && !property.PropertyType.IsValueType()
where (property.GetGetMethod() != null) && (property.GetSetMethod() != null) && !property.PropertyType.IsValueType() && property.GetCustomAttributes(typeof(TinyIocInjectAttribute), true).Any()
select property;

foreach (var property in properties)
Expand Down
2 changes: 2 additions & 0 deletions src/FreshIOC/IOC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<AssemblyName>FreshIOC</AssemblyName>
<TargetFrameworkProfile>Profile14</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<ReleaseVersion>2.2.0</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -32,6 +33,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FreshTinyIOC.cs" />
<Compile Include="IRegisterOptions.cs" />
<Compile Include="TinyIocInjectAttribute.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>
7 changes: 7 additions & 0 deletions src/FreshIOC/TinyIocInjectAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;
namespace FreshTinyIoC
{
public class TinyIocInjectAttribute : Attribute
{
}
}
2 changes: 1 addition & 1 deletion src/FreshMvvm/FreshPageModelResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static Page ResolvePageModel<T> () where T : FreshBasePageModel
public static Page ResolvePageModel<T> (object initData) where T : FreshBasePageModel
{
var pageModel = FreshIOC.Container.Resolve<T> ();

return ResolvePageModel<T> (initData, pageModel);
}

Expand All @@ -33,6 +32,7 @@ public static Page ResolvePageModel (Type type, object data)

public static Page ResolvePageModel (Type type, object data, FreshBasePageModel pageModel)
{
FreshIOC.Container.BuildUp(ref pageModel);
var name = PageModelMapper.GetPageTypeName (type);
var pageType = Type.GetType (name);
if (pageType == null)
Expand Down
17 changes: 14 additions & 3 deletions src/FreshMvvm/FreshTinyIOCBuiltIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ public IRegisterOptions Register<RegisterType>(RegisterType instance) where Regi

public ResolveType Resolve<ResolveType>(string name) where ResolveType : class
{
return FreshTinyIoCContainer.Current.Resolve<ResolveType> (name);
var result = FreshTinyIoCContainer.Current.Resolve<ResolveType>(name);
BuildUp(ref result);
return result;
}

public ResolveType Resolve<ResolveType>() where ResolveType : class
{
return FreshTinyIoCContainer.Current.Resolve<ResolveType> ();
var result = FreshTinyIoCContainer.Current.Resolve<ResolveType>();
BuildUp(ref result);
return result;
}

public IRegisterOptions Register<RegisterType, RegisterImplementation> ()
Expand All @@ -45,7 +49,14 @@ public IRegisterOptions Register<RegisterType, RegisterImplementation> ()

public object Resolve(Type resolveType)
{
return FreshTinyIoCContainer.Current.Resolve (resolveType);
var result = FreshTinyIoCContainer.Current.Resolve (resolveType);
BuildUp(ref result);
return result;
}

public void BuildUp<ResolveType>(ref ResolveType input) where ResolveType : class
{
FreshTinyIoCContainer.Current.BuildUp(input);
}

public void Unregister<RegisterType>()
Expand Down
1 change: 1 addition & 0 deletions src/FreshMvvm/IOC/IFreshIOC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace FreshMvvm
public interface IFreshIOC
{
object Resolve(Type resolveType);
void BuildUp<ResolveType>(ref ResolveType input) where ResolveType : class;
IRegisterOptions Register<RegisterType>(RegisterType instance) where RegisterType : class;
IRegisterOptions Register<RegisterType>(RegisterType instance, string name) where RegisterType : class;
ResolveType Resolve<ResolveType>() where ResolveType : class;
Expand Down